layui.use(['form','jquery',"layer"],function() {
    var form = layui.form,
        $ = layui.jquery,
        layer = parent.layer === undefined ? layui.layer : top.layer;

    //非管理员登录屏蔽操作按钮
    if(localStorage.getItem("IS_ADMIN")==0){
        $(".save").remove();
    }

    //获取当前系统支付配置
    Common.invoke({
        url : request('/console/payConfig'),
        data : {},
        successMsg : false,
        errorMsg : "获取数据失败,请检查网络",
        success : function(result) {
            fillParameter(result.data);
        },
        error : function(result) {
        }

    });

    form.on("submit(walletConfig)",function(){
        var payConfig = {};
        payConfig.id = 10000;
        payConfig.maxTransferAmount = $(".maxTransferAmount").val();
        payConfig.maxRedpacktAmount = $(".maxRedpacktAmount").val();
        payConfig.maxRedpacktNumber = $(".maxRedpacktNumber").val();
        payConfig.maxWithdrawAmount = $(".maxWithdrawAmount").val();
        payConfig.maxRechargeAmount = $(".maxRechargeAmount").val();
        payConfig.maxCodePaymentAmount = $(".maxCodePaymentAmount").val();
        payConfig.maxCodeReceiptAmount = $(".maxCodeReceiptAmount").val();
        payConfig.dayMaxTransferAmount = $(".dayMaxTransferAmount").val();
        payConfig.dayMaxRedpacktAmount = $(".dayMaxRedpacktAmount").val();
        payConfig.dayMaxWithdrawAmount = $(".dayMaxWithdrawAmount").val();
        payConfig.dayMaxRechargeAmount = $(".dayMaxRechargeAmount").val();
        payConfig.dayMaxCodePayAmount = $(".dayMaxCodePayAmount").val();
        payConfig.dayMaxCodeReceiptAmount = $(".dayMaxCodeReceiptAmount").val();
        payConfig.isOpenManualPay = $(".isOpenManualPay").val();
        payConfig.isOpenCloudWallet = $(".isOpenCloudWallet").val();
        payConfig.isDefaultFreeze = $(".isDefaultFreeze").val();
        payConfig.myChangeWithdrawRate = $(".myChangeWithdrawRate").val();
        payConfig.newYopUserRechargeTime = $(".newYopUserRechargeTime").val();
        payConfig.newYopUserFirstRecharge = $(".newYopUserFirstRecharge").val();
        payConfig.consoleMaxRechargeAmount = $(".consoleMaxRechargeAmount").val();
        payConfig.consoleMaxCodePaymentAmount = $(".consoleMaxCodePaymentAmount").val();
        payConfig.manualPaywithdrawFee = $(".manualPaywithdrawFee").val();
        payConfig.rechargePresentedScale = $(".rechargePresentedScale").val();
        payConfig.upayWithdrawServiceCharge = $(".upayWithdrawServiceCharge").val();
        payConfig.minWithdrawAmount = $(".minWithdrawAmount").val();
        payConfig.isOpenAuditPay = $(".isOpenAuditPay").val();
        payConfig.isOpenAutoPay = $(".isOpenAutoPay").val();
        payConfig.isOpenWXPay = $(".isOpenWXPay").val();
        payConfig.minRechargeAmount = $(".minRechargeAmount").val();
        payConfig.myChangeWithdrawBase = $(".myChangeWithdrawBase").val();
        payConfig.isOpenDepositWithdrawal = $(".isOpenDepositWithdrawal").val();
        payConfig.isOpenCZ = $(".isOpenCZ").val();

        payConfig.rechargeIntervalMin = $(".rechargeIntervalMin").val();
        payConfig.rechargeIntervalMax = $(".rechargeIntervalMax").val();

        payConfig.secondRechargeIntervalMin = $(".secondRechargeIntervalMin").val();
        payConfig.secondRechargeIntervalMax = $(".secondRechargeIntervalMax").val();

        payConfig.qqf = $(".qqf").val()
        payConfig.qqs = $(".qqs").val()

        payConfig.atlsf = $(".atlsf").val()
        payConfig.atlss = $(".atlss").val()

        payConfig.numf = $(".numf").val()
        payConfig.nums = $(".nums").val()


        payConfig.bankpf = $(".bankpf").val()
        payConfig.bankps = $(".bankps").val()

        payConfig.zfbf = $(".zfbf").val()
        payConfig.zfbs = $(".zfbs").val()

        payConfig.bankp2f = $(".bankp2f").val()
        payConfig.bankp2s = $(".bankp2s").val()


        payConfig.zfb2f = $(".zfb2f").val()
        payConfig.zfb2s = $(".zfb2s").val()

        payConfig.zhf = $(".zhf").val()
        payConfig.zhs = $(".zhs").val()

        payConfig.usdtf = $(".usdtf").val()
        payConfig.usdts = $(".usdts").val()

        if($(".manualPaywithdrawFee").val() == ""){
            layer.alert("提现费率不能为空");
            return;
        }else if($(".manualPaywithdrawFee").val() > 1){
            layer.alert("提现费率要小于1");
            return;
        }

        if($(".rechargeIntervalMin").val() == ""){
            payConfig.rechargeIntervalMin = 10
        }else if($(".rechargeIntervalMin").val() < 10 || $(".rechargeIntervalMin").val() > 1000){
            layer.alert("app支付宝首充充值最小金额要大于10少于1000");
            return;
        }

        if($(".rechargeIntervalMax").val() == ""){
            payConfig.rechargeIntervalMax = 1000
        }else if($(".rechargeIntervalMax").val() < 10 || $(".rechargeIntervalMax").val() > 1000){
            layer.alert("app支付宝首充充值最大金额要大于10少于1000");
            return;
        }

        if(payConfig.rechargeIntervalMax < payConfig.rechargeIntervalMin){
            layer.alert("app支付宝充值首充最大金额不能少于最小金额");
            return;
        }


        if($(".secondRechargeIntervalMin").val() == ""){
            payConfig.secondRechargeIntervalMin = 10
        }else if($(".secondRechargeIntervalMin").val() < 10 || $(".secondRechargeIntervalMin").val() > 1000){
            layer.alert("app支付宝二充充值最小金额要大于10少于1000");
            return;
        }

        if($(".secondRechargeIntervalMax").val() == ""){
            payConfig.secondRechargeIntervalMax = 1000
        }else if($(".secondRechargeIntervalMax").val() < 10 || $(".secondRechargeIntervalMax").val() > 1000){
            layer.alert("app支付宝二充充值最大金额要大于10少于1000");
            return;
        }

        if(payConfig.secondRechargeIntervalMax < payConfig.secondRechargeIntervalMin){
            layer.alert("app支付宝二充充值最大金额不能少于最小金额");
            return;
        }

        Common.invoke({
            url : request('/console/payConfig/set'),
            data : payConfig,
            successMsg : "操作成功",
            errorMsg : "操作失败,请检查网络",
            success : function(result) {

            },
            error : function(result) {

            }

        });
        return false;
    })

});

function fillParameter(data){
    //判断字段数据是否存在
    function nullData(data){
        if(data == '' || data == "undefined" || data==null){
            return "";
        }else{
            return data;
        }
    }
    // 数据回现
    $(".maxTransferAmount").val(data.maxTransferAmount);
    $(".maxRedpacktAmount").val(data.maxRedpacktAmount);
    $(".maxRedpacktNumber").val(data.maxRedpacktNumber);
    $(".maxWithdrawAmount").val(data.maxWithdrawAmount);
    $(".maxRechargeAmount").val(data.maxRechargeAmount);
    $(".maxCodePaymentAmount").val(data.maxCodePaymentAmount);
    $(".maxCodeReceiptAmount").val(data.maxCodeReceiptAmount);
    $(".dayMaxTransferAmount").val(data.dayMaxTransferAmount);
    $(".dayMaxRedpacktAmount").val(data.dayMaxRedpacktAmount);
    $(".dayMaxWithdrawAmount").val(data.dayMaxWithdrawAmount);
    $(".dayMaxRechargeAmount").val(data.dayMaxRechargeAmount);
    $(".dayMaxCodePayAmount").val(data.dayMaxCodePayAmount);
    $(".dayMaxCodeReceiptAmount").val(data.dayMaxCodeReceiptAmount);
    $(".isOpenManualPay").val(data.isOpenManualPay);
    $(".isOpenCloudWallet").val(data.isOpenCloudWallet);
    $(".isDefaultFreeze").val(data.isDefaultFreeze);
    $(".myChangeWithdrawRate").val(data.myChangeWithdrawRate);
    $(".newYopUserRechargeTime").val(data.newYopUserRechargeTime);
    $(".newYopUserFirstRecharge").val(data.newYopUserFirstRecharge);
    $(".consoleMaxRechargeAmount").val(data.consoleMaxRechargeAmount);
    $(".consoleMaxCodePaymentAmount").val(data.consoleMaxCodePaymentAmount);
    $(".manualPaywithdrawFee").val(data.manualPaywithdrawFee);
    $(".rechargePresentedScale").val(data.rechargePresentedScale);
    $(".upayWithdrawServiceCharge").val(data.upayWithdrawServiceCharge);
    $(".minWithdrawAmount").val(data.minWithdrawAmount);
    $(".isOpenAuditPay").val(data.isOpenAuditPay);
    $(".isOpenAutoPay").val(data.isOpenAutoPay);
    $(".isOpenWXPay").val(data.isOpenWXPay);
    $(".minRechargeAmount").val(data.minRechargeAmount);
    $(".myChangeWithdrawBase").val(data.myChangeWithdrawBase);
    $(".isOpenCZ").val(data.isOpenCZ);
    $(".isOpenDepositWithdrawal").val(data.isOpenDepositWithdrawal);

    $(".rechargeIntervalMin").val(data.rechargeIntervalMin);
    $(".rechargeIntervalMax").val(data.rechargeIntervalMax);

    $(".secondRechargeIntervalMin").val(data.secondRechargeIntervalMin);
    $(".secondRechargeIntervalMax").val(data.secondRechargeIntervalMax);

    $(".qqf").val(data.qqf);
    $(".qqs").val(data.qqs);

    $(".atlsf").val(data.atlsf);
    $(".atlss").val(data.atlss);

    $(".numf").val(data.numf);
    $(".nums").val(data.nums);

    $(".bankpf").val(data.bankpf);
    $(".bankps").val(data.bankps);

    $(".zfbf").val(data.zfbf);
    $(".zfbs").val(data.zfbs);


    $(".bankp2f").val(data.bankp2f);
    $(".bankp2s").val(data.bankp2s);


    $(".zfb2f").val(data.zfb2f);
    $(".zfb2s").val(data.zfb2s);

    $(".zhf").val(data.zhf);
    $(".zhs").val(data.zhs);


    $(".usdtf").val(data.usdtf);
    $(".usdts").val(data.usdts);

    //重新渲染
    layui.form.render();
}
$(function () {
    //权限判断
    var arr=['pay-sava'];
    manage.authButton(arr);
    //调用父级页面的Js函数
    window.parent.getJointVisitPath();
})